package learning.directory.Work.排序.Nf;

import java.util.Arrays;

/**
 * @author NIEF
 */
public class InsertSortDay3 {

    public static void main(String[] args) {
        int[] arrSort = {49, 38, 65, 97, 23, 22, 76, 1};
        //InsertSort(arrSort);
        insertion1(arrSort);
        System.out.println(Arrays.toString(arrSort));
    }


    private static void InsertSort(int[] arrSort) {
        for (int i = 1; i < arrSort.length; i++) {
            int temp = arrSort[i];
            int j;
            for (j = i - 1; j >= 0 && arrSort[j] > temp; j--) {
                arrSort[j + 1] = arrSort[j];
            }
            arrSort[j + 1] = temp;
        }
    }

    public static void insertion1(int[] arrSort) {
        for (int i = 1; i < arrSort.length; i++) {
            int temp = arrSort[i];
            int j = i - 1;
            while (j >= 0 && arrSort[j] > temp) {
                arrSort[j + 1] = arrSort[j];
                j--;
            }
            arrSort[j + 1] = temp;
        }

    }
}